package edu.bupt.changelog.demo.service;

import edu.bupt.changelog.history.HistoryEntity;
import edu.bupt.changelog.history.anno.HistoryGet;
import edu.bupt.changelog.history.anno.HistoryPut;
import edu.bupt.changelog.demo.service.dto.AddRequestRequest;
import edu.bupt.changelog.demo.service.dto.RequestDO;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class RequestService {
    public static Map<Long, RequestDO> map = new HashMap<>();

    @HistoryPut(HistoryEntity.REQUEST)
    public void put(AddRequestRequest addRequestRequest){
        RequestDO requestDo = new RequestDO();
        requestDo.setRequestId(addRequestRequest.getRequestId());
        requestDo.setAddress(addRequestRequest.getAddress());
        requestDo.setName(addRequestRequest.getName());
        map.put(requestDo.getRequestId(),requestDo);
    }

    @HistoryGet(HistoryEntity.REQUEST)
    public RequestDO get(long bizId){
        RequestDO requestDO = map.get(bizId);
        return requestDO;
    }

    @HistoryPut(HistoryEntity.REQUEST)
    public void del(long bizId){
        map.remove(bizId);
    }
}
